import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

export default new Vuex.Store({
	state: {
		rataData: [
      { zh: '人民币', en: 'CNY', isSelect: '已选', rate: '1', value: ''},
      { zh: '美元', en: 'USD', isSelect: '已选', rate: '0.1439', value: '' },
      { zh: '港元', en: 'HKD', isSelect: '已选', rate: '1.1281', value: '' },
      { zh: '日元', en: 'JPY', isSelect: '', rate: '16.0924', value: '' },
      { zh: '英镑', en: 'GBP', isSelect: '', rate: '0.1121', value: '' },
      { zh: '欧元', en: 'EUR', isSelect: '', rate: '0.1263', value: '' }
    ],
    navData: [
    	{ headtitle: '汇率换算', text: '换算', icon: 'icon-shouzhimingxicaifuhongbaoyue', link: 'index' },
      { headtitle: '个人中心', text: '我的', icon: 'icon-user3', link: 'personal' },
    ],
    title: ''
	},
	mutations: {
		changeRata (state, key) {
			for (var i = 0; i < state.rataData.length; i++) {
				if (key[1] === state.rataData[i].rate) {
					state.rataData[i].value = key[0]
				} else {
					state.rataData[i].value = (state.rataData[i].rate  / key[1] * key[0]).toFixed(2)
				}
			}
		},
		changeSelect (state, key) {
			for (var i = 0; i < state.rataData.length; i++) {
				if (key === state.rataData[i].en) {
					state.rataData[i].isSelect = '已选'
				}
			}
		},
		removeRata (state, key) {
			for (var i = 0; i < state.rataData.length; i++) {
				if (key === state.rataData[i].en) {
					state.rataData[i].isSelect = ''
				}
			}
		},
		changeTitle (state, key) {
			state.title = key
		}
	},
	getters: {
	},
	actions: {
	}
})
